
function getoperation(time) {
// console.log(time,"time")
if(!time){
    time = []
}
  $.ajax({
    url: baseUrl + "/typeList",
    type: "POST",
    dataType: "json",
    data: {
        start_date:time[0],
        end_date:time[1]
    },
    success: (data) => {
      let res = data.data.list.filter(item=> item.num!=0)
      data.data.list = res
      operationData(data.data);
    },
    // 超时时间
    timeout: 4000,
    // 失败的回调
    error: function () {
      clearInterval(interval);
      // alert("请求数据失败！");
    },
  });
}
//获取数据
function operationData(res) {
  let m =res
  let a = res.list.map((item)=>{
    if(item.type_name.length<10){
        let r = item.type_name.length

        for(var i = 1;i<=10-r;i++){
            item.type_name += ' ';
        }
        for(var i = 1;i<=(10-r)*2;i++){
            item.num += ' ';
        }
    }
    console.log(item.type_name,item.type_name.length,'a')
    return {
      value:' '+item.num + '    ' + item.rate +"%",
      name:item.type_name+'   '+'占比'+"\n",
      
    }
  })
  
  let b = res.total
  let c = m.list.map((item)=>{
      return{
           value:item.num,
            name:item.type_name+'   '+'占比'+"\n",
      }
  })
//   console.log(a,'a',c)
  var optionData = operationEcharts(a)
  operationEcharts(a,b,c);
  // operationList(res.all);
}
function array2obj(array,key) {
	var resObj = {};
	for(var i=0;i<array.length;i++){
		resObj[array[i][key]] = array[i];
	}
	return resObj;
}

//echarts 数据渲染
function operationEcharts(a,b,c) {
  var objData = array2obj(a, "name");
  var option = {
    title: {
      text: '项目总数' + '\n'+' '+b,
      x: '24.8%',
      y: 'center',
      textAlign:'center',
      textStyle: {
          fontSize: 14,
          color:'#fff'
      }
    },
    legend: {
     icon:"rect",
     itemWidth:14,
     itemHeight:14,
      orient: "vertical",
      x: '54%',
      y: 'center',
      padding:[0,0,0,30], 
    
        formatter: function(name) {
            return "{title|" + name + "}\n{value|" + (objData[name].value) +"}"
        },
       
        textStyle: {
            rich: {
                title: {
                    fontSize: 13,
                    lineHeight: 8,
                    color: "#fff"
                },
                value: {
                    fontSize: 13,
                    lineHeight: 8,
                    color: "rgb(0, 178, 246)"
                }
            }
        },
    },
    // 
    
    tooltip: {
      trigger: 'item',
    //   extraCssText:'width:170px; white-space:pre-wrap',
      
      formatter: (params) => {//自定义样式
    //   console.log(params,'params')
        let res = "<div>" + 
            "<div>" + params.name + "</div>"+
            "<div>" + params.value + "      " +  params.percent.toFixed(0) +  "%</div>"+
          "</div>";
        return res;
      }
    // formatter:"{b}"
    //   {b0}: {c0}<br />{b1}: {c1}
    },
   
    series: [
      {
        type: 'pie',
        radius: ['16%', '40%'],
        center: ['26%', '50%'],
        roseType: 'area',
        data: c,
        label: {
          show: false,
        },
        labelLine:{
          show:false,
        },
        minAngle: 10,
      }
    ]
  };
  chartDom_o = document.getElementById("operation");
  myChart_o = echarts.init(chartDom_o);
//   myChart_o.setOption(option);
// 设置自适应屏幕大小
//window.onresize = myChart.resize;
  myChart_o.setOption(option, true, true);
    window.addEventListener("resize", function() {
    myChart_o.resize();
});
}

